inspector: Replace reload with record
authorBenjamin Otte <otte@redhat.com>
Tue, 14 Oct 2014 12:01:42 +0000 (14:01 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 14 Oct 2014 12:03:06 +0000 (14:03 +0200)
and when pressed, record instance counts at 1fps.

gtk/inspector/statistics.c
gtk/inspector/statistics.ui
gtk/inspector/statistics.ui.h

index 628c644322583881540a76edca20a6bbd5c116a6..69c4bc8f9228506ce39908e36acc7acd251f1041 100644 (file)
@@ -42,6 +42,7 @@ struct _GtkInspectorStatisticsPrivate
   GtkTreeViewColumn *column_cumulative2;
   GtkCellRenderer *renderer_cumulative2;
   GHashTable *counts;
+  guint update_source_id;
 };
 
 typedef struct {
@@ -113,9 +114,10 @@ add_type_count (GtkInspectorStatistics *sl, GType type)
   return cumulative;
 }
 
-static void
-update_type_counts (GtkInspectorStatistics *sl)
+static gboolean
+update_type_counts (gpointer data)
 {
+  GtkInspectorStatistics *sl = data;
   GType type;
   gpointer class;
 
@@ -130,12 +132,29 @@ update_type_counts (GtkInspectorStatistics *sl)
 
       add_type_count (sl, type);
     }
+
+  return TRUE;
 }
 
 static void
-refresh_clicked (GtkWidget *button, GtkInspectorStatistics *sl)
+toggle_record (GtkToggleToolButton    *button,
+               GtkInspectorStatistics *sl)
 {
-  update_type_counts (sl);
+  if (gtk_toggle_tool_button_get_active (button) == (sl->priv->update_source_id != 0))
+    return;
+
+  if (gtk_toggle_tool_button_get_active (button))
+    {
+      sl->priv->update_source_id = gdk_threads_add_timeout_seconds (1,
+                                                                    update_type_counts,
+                                                                    sl);
+      update_type_counts (sl);
+    }
+  else
+    {
+      g_source_remove (sl->priv->update_source_id);
+      sl->priv->update_source_id = 0;
+    }
 }
 
 static gboolean
@@ -250,6 +269,9 @@ finalize (GObject *object)
 {
   GtkInspectorStatistics *sl = GTK_INSPECTOR_STATISTICS (object);
 
+  if (sl->priv->update_source_id)
+    g_source_remove (sl->priv->update_source_id);
+
   g_hash_table_unref (sl->priv->counts);
 
   G_OBJECT_CLASS (gtk_inspector_statistics_parent_class)->finalize (object);
@@ -276,7 +298,7 @@ gtk_inspector_statistics_class_init (GtkInspectorStatisticsClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, column_cumulative2);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, renderer_cumulative2);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, button);
-  gtk_widget_class_bind_template_callback (widget_class, refresh_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, toggle_record);
 }
 
 // vim: set et sw=2 ts=2:
index 7c4ca20fe60c196b1484ea43f2978447c171a4a9..9e72d45c8f15fe903bc3b373fb38b50aedfc2ddc 100644 (file)
                 <property name="visible">True</property>
                 <property name="icon-size">small-toolbar</property>
                 <child>
-                  <object class="GtkToolButton" id="button">
+                  <object class="GtkToggleToolButton" id="button">
                     <property name="visible">True</property>
-                    <property name="icon-name">view-refresh-symbolic</property>
-                    <property name="tooltip-text" translatable="yes">Refresh</property>
-                    <signal name="clicked" handler="refresh_clicked"/>
+                    <property name="icon-name">media-record-symbolic</property>
+                    <property name="tooltip-text" translatable="yes">Collect Statistics</property>
+                    <signal name="toggled" handler="toggle_record"/>
                   </object>
                 </child>
               </object>
index b1fbb465424ec8ab18034e4a56cfcc4322d7df0b..c93734611d5c16b35f7f1875058d24d44f27ef6a 100644 (file)
@@ -1,4 +1,4 @@
-N_("Refresh");
+N_("Collect Statistics");
 N_("Type");
 N_("Self 1");
 N_("Cumulative 1");
@@ -6,4 +6,6 @@ N_("Self 2");
 N_("Cumulative 2");
 N_("Self");
 N_("Cumulative");
+N_("Self");
+N_("Cumulative");
 N_("Enable statistics with GOBJECT_DEBUG=instance-count");